<template>
  <div>
    <div class="update-gender">
      <van-picker
        show-toolbar
        title="标题"
        :columns="sex"
        :default-index="value"
        @cancel="$emit('close')"
        @confirm="onConfirm"
      />
    </div>
  </div>
</template>

<script>
import { updategender } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      sex: ['男', '女'],
      gender: ''
    }
  },

  created() {
    // this.gender = this.value
    console.log(this.value)
  },

  methods: {
    async  onConfirm(val, index) {
      this.$toast.loading({
        message: '更新中...',
        forbidClick: true, // 禁止背景点击
        duration: 0 // 持续展示
      })

      console.log(val, index)
      try {
        const res = await updategender({
          gender: index
        })
        console.log(res)
        this.$emit('updatsex', index)
        Toast.success('cg')
      } catch (err) {
        console.log(err)
        Toast.fail('sb')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
